import utils from '../utils'
import Dataset from '../dataset'

function setCoordinatePrecision(dataset, precision) {
  const round = getRoundingFunction(precision)
  // var dissolvePolygon, nodes;
  Dataset.transformPoints(dataset, (x, y) => {
    return [round(x), round(y)]
  })
  return dataset
}
function getRoundingFunction(inc) {
  if (!utils.isNumber(inc) || inc === 0) {
    utils.error("Rounding increment must be a non-zero number.")
  }
  let inv = 1 / inc
  if (inv > 1) inv = Math.round(inv)
  return function(x) {
    return Math.round(x * inv) / inv
  }
}

export default {
  setCoordinatePrecision,
  getRoundingFunction,
}